package com.skt.common_hr.common.components
{
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	
	import mx.containers.Panel;
	import mx.controls.Button;
	
	public class CommonPanel extends Panel{
		
		public function CommonPanel()
		{
			super();
		}
		
		[Embed(source="/assets/images/btn_close_up.png")]
	    private var closeIcon:Class;
	    [Embed(source="/assets/images/btn_close_down.png")]
	    private var closeIcon_down:Class;
	    [Embed(source="/assets/images/btn_close_over.png")]
	    private var closeIcon_over:Class;
	    
		private var _closeFunc:Function = null;
		public function set closeFunc(func:Function):void{
			_closeFunc = func;
		}
		
		override protected function createChildren():void{
			super.createChildren();
			this.setStyle("paddingLeft", 5);
			this.setStyle("paddingRight", 5);
			this.setStyle("paddingTop", 5);
			this.setStyle("paddingBottom", 5);
			setCloseButton();
		   	this.setFocus();
		}
		
		public function get actualHeight():Number
		{
			return this.height - 100; 			
		}
		
		private function setCloseButton():void
		{
		   	var closeBtn:Button = new Button();
		   	if(_closeFunc != null){
			   	closeBtn.addEventListener("click",_closeFunc);
			   	this.addEventListener(KeyboardEvent.KEY_DOWN, escKeyEvent);
		   	}
		    closeBtn.setStyle("upSkin",closeIcon);
		    closeBtn.setStyle("downSkin",closeIcon_down);
		    closeBtn.setStyle("overSkin",closeIcon_over);
		    closeBtn.buttonMode = true;
		   	closeBtn.setActualSize(25,22);
		   	closeBtn.x = this.width - 34;
		   	closeBtn.y = 8;
		   	rawChildren.addChild(closeBtn);
		}
		
		private function escKeyEvent(event:KeyboardEvent):void{
			if(event.keyCode == Keyboard.ESCAPE){
				//_closeFunc();
			}
		}
	}
}